home *** CD-ROM | disk | FTP | other *** search
- Path: chronicle.mti.sgi.com!austern
- From: clamage@Eng.Sun.COM (Steve Clamage)
- Newsgroups: comp.std.c++
- Subject: Re: Single-line comment and line continuation
- Date: 04 Mar 1996 11:22:32 PST
- Organization: Sun Microsystems Inc.
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <4hffkm$3f0@engnews1.Eng.Sun.COM>
- References: <313B3175.331A@strata3d.com>
- Reply-To: clamage@Eng.Sun.COM
- NNTP-Posting-Host: isolde.mti.sgi.com
- X-Original-Date: 4 Mar 1996 19:17:42 GMT
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMTtDJky4NqrwXLNJAQHTvAIAmKLPL67LhQ5Vhd804vESSjUeTpHSd4GY
- REw/ufuzIrPW69x5CRk9Lia6DgZKAw2kt4n4xmO3odHlbohIzVNA8A==
- =hiGH
- Originator: austern@isolde.mti.sgi.com
-
- In article 331A@strata3d.com, Bret Pehrson <BretP@strata3d.com> writes:
- >I just ran across something in my C++ compiler dealing with single line
- >comments and the line continuation token:
- >
- > if ((ch[0] == '\\') && (ch[1] == '\\')) //look for initial \\
- > {
- > ...
- >
- >This, under my compiler implementation will choke because of the line
- >continuation token, '\' at the end of the comment.
- >
- >Can someone please look in their copy of the current C++ 'standard' and tell
- >me if this is correct?
-
- Yes, it is a consequence of the phases of translation. Escaped newlines
- are handled by pasting lines together before comments are removed, the
- same as in C. (When C adds '//' comments, I expect it to have the same
- behavior.)
-
- The phases of translation were very carefully worked out by the ANSI C
- committee for the C standard, and any change causes various things to break
- or otherwise behave strangely. The fragility is due to interactions among
- trigraphs
- escaped newlines
- escaped characters in strings or character constants
- macro expansion.
-
- In C++, simply don't use '//' comments on any line that ends with an
- escaped newline (including macro definitions!). In your example, it would
- make the comment more readable IMHO if you put the '\\' in quotes anyway,
- and would eliminate the problem.
-
- ---
- Steve Clamage, stephen.clamage@eng.sun.com
- ---
- [ comp.std.c++ is moderated. To submit articles: Try just posting with your
- newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
- comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
- Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-